package com.apusic.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.apusic.common.Constants;
import com.apusic.entity.TSystemUser;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;


@Controller
public class IndexController {
	@RequestMapping(value = "/")
	public String show(HttpServletRequest request,HttpServletResponse response) {
		try {
			response.sendRedirect("/index");
		} catch (IOException e) {
			e.printStackTrace();
			return "redirect:/index";
		}
		return null;
	}
	/**
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/index")
	public String showIndex(HttpServletRequest request,
			HttpServletResponse response) {
		TSystemUser user = (TSystemUser) request.getSession().getAttribute(Constants.Session_key);
		try {
			if(null==user){
				response.sendRedirect("/login");
				//return "redirect:/login";
			}else{
				response.sendRedirect("/loginning");
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
		//return "redirect:/loginning";
	}
	@RequestMapping(value = "/home")
	public String showHome(HttpServletRequest request,
			HttpServletResponse response) {
		return "/home/home";
	}
}
